package com.lucky.back.service.impl;

import com.lucky.back.ex.ServiceException;
import com.lucky.back.mapper.OrdersMapper;
import com.lucky.back.mapper.ProductCategoryMapper;
import com.lucky.back.pojo.dto.OrderAddNewDTO;
import com.lucky.back.pojo.dto.ProductCategoryAddNewDTO;
import com.lucky.back.pojo.entity.Orders;
import com.lucky.back.pojo.entity.Productcategory;
import com.lucky.back.pojo.vo.OrderListItenVO;
import com.lucky.back.pojo.vo.OrderStandardVO;
import com.lucky.back.pojo.vo.ProductCategoryListItemVO;
import com.lucky.back.pojo.vo.ProductCategoryStandardVO;
import com.lucky.back.service.ICategoryService;
import com.lucky.back.service.IOrdersService;
import com.lucky.back.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class OrdersServiceImpl implements IOrdersService {

    @Autowired
    OrdersMapper ordersMapper;

    @Override
    public List<OrderListItenVO> selectById(Long id) {
        List<OrderListItenVO> list = ordersMapper.selectById(id);
        return list;
    }

    @Override
    public void addNew(OrderAddNewDTO orderAddNewDTO) {
        Orders orders = new Orders();
        BeanUtils.copyProperties(orderAddNewDTO,orders);
        log.debug("2222222222222222");
        System.out.println("即将执行插入service");
        ordersMapper.insert(orders);
    }

    @Override
    public void delete(Long id) {
        log.debug("开始处理删除请求");
        OrderStandardVO queruResult = ordersMapper.getStandardById(id);
        if (queruResult == null){
            String message = "删除失败,,尝试访问数据不存在!";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERR_NOT_FOUND,message);
        }
        log.debug("即将删除数据");
        ordersMapper.deleteById(id);
        log.debug("删除，完成！");
    }

    @Override
    public List<OrderListItenVO> list() {
        log.debug("查询种类列表服务层——————————————————");
        return ordersMapper.list();
    }
}
